package com.searchtree.binarysearchtree;

import com.searchtree.tree.AbstractNode;
import com.searchtree.tree.LeafNode;

public class BinarySearchTreeNode extends AbstractNode
{
	private String       key;
	private AbstractNode leftNode;
	private AbstractNode rightNode;
	
	public BinarySearchTreeNode(String key)
	{
		this.setKey(key);
		this.leftNode  = new LeafNode();
		this.rightNode = new LeafNode();
	}

	public String getKey()
	{
		return key;
	}

	public void setKey(String key)
	{
		this.key = key;
	}

	public AbstractNode getRightNode()
	{
		return rightNode;
	}

	public void setRightNode(AbstractNode rightNode)
	{
		this.rightNode = rightNode;
	}

	public AbstractNode getLeftNode()
	{
		return leftNode;
	}

	public void setLeftNode(AbstractNode leftNode)
	{
		this.leftNode = leftNode;
	}
	
	public String toString()
	{
		String message = "Key: " + key; 
		
		if(leftNode instanceof LeafNode){
			message += "\n Left child is a leafnode";
		}
		else 
		{
			message += "\n Left child has key: " + ((BinarySearchTreeNode) leftNode).getKey();
		}
		
		if(rightNode instanceof LeafNode)
		{
			message += "\n Right child is a leafnode";
		}
		else 
		{
			message += "\n Right child has key: " + ((BinarySearchTreeNode) rightNode).getKey();
		}
		
		return message;
	}
}
